﻿using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using System.Threading;
using System.Diagnostics;

namespace BigNumber.NUnitTests
{

  [TestFixture]
  public class NUnitFactoringBigNumberTests
  {
    private static int NUMBER_LENGTH = 50;
    [Test]
    public void TestFactoringBigNumberCreatoin()
    {
      FactoringBigNumber number1;
      StdBigNumber number2;
      for (int i = 0; i < TestsHelper.TEST_COUNT; i++)
      {
        string tempNumber = TestsHelper.GenerateRandomNumber(NUMBER_LENGTH, 1);
        number1 = new FactoringBigNumber(tempNumber);
        number2 = new StdBigNumber(tempNumber);
        Assert.IsTrue(number1.ToString() == number2.ToString());
      }
    }

    [Test]
    public void TestFactoringBigNumberSum()
    {
      FactoringBigNumber number1;
      StdBigNumber number2;
      for (int i = 0; i < TestsHelper.TEST_COUNT; i++)
      {
        string tempNumber1 = TestsHelper.GenerateRandomNumber(NUMBER_LENGTH, 1);
        string tempNumber2 = TestsHelper.GenerateRandomNumber(NUMBER_LENGTH, 1);
        number1 = (new FactoringBigNumber(tempNumber1)) + (new FactoringBigNumber(tempNumber2));
        number2 = (new StdBigNumber(tempNumber1)) + (new StdBigNumber(tempNumber2));
        Assert.IsTrue(number1.ToString() == number2.ToString(), String.Format("FactoringBigNumber was {0} and StdBigNumber was {1}", number1.ToString(), number2.ToString()));
      }
    }

    [Test]
    public void TestFactoringBigNumberSub()
    {
      FactoringBigNumber number1;
      StdBigNumber number2;
      for (int i = 0; i < TestsHelper.TEST_COUNT; i++)
      {
        string tempNumber1 = TestsHelper.GenerateRandomNumber(NUMBER_LENGTH, 1);
        string tempNumber2 = TestsHelper.GenerateRandomNumber(NUMBER_LENGTH, 1);
        number1 = (new FactoringBigNumber(tempNumber1)) - (new FactoringBigNumber(tempNumber2));
        number2 = (new StdBigNumber(tempNumber1)) - (new StdBigNumber(tempNumber2));
        Assert.IsTrue(number1.ToString() == number2.ToString(), String.Format("FactoringBigNumber was {0} and StdBigNumber was {1} while doing {2} - {3}", number1.ToString(), number2.ToString(),tempNumber1,tempNumber2));
      }
    }

    [Test]
    public void TestFactoringBigNumberMul()
    {
      FactoringBigNumber number1;
      StdBigNumber number2;
      for (int i = 0; i < TestsHelper.TEST_COUNT; i++)
      {
        string tempNumber1 = TestsHelper.GenerateRandomNumber(NUMBER_LENGTH, 1);
        string tempNumber2 = TestsHelper.GenerateRandomNumber(NUMBER_LENGTH, 1);
        number1 = (new FactoringBigNumber(tempNumber1)) * (new FactoringBigNumber(tempNumber2));
        number2 = (new StdBigNumber(tempNumber1)) * (new StdBigNumber(tempNumber2));
        Assert.IsTrue(number1.ToString() == number2.ToString(), String.Format("FactoringBigNumber was {0} and StdBigNumber was {1} when doing {2} * {3}", number1.ToString(), number2.ToString() ,tempNumber1,tempNumber2));
      }
    }

    //[Test]
    //public void TestFactoringBigNumberDiv()
    //{
    //  FactoringBigNumber number1;
    //  StdBigNumber number2;
    //  Random rnd = new Random();
    //  for (int i = 0; i < TestsHelper.TEST_COUNT; i++)
    //  {
    //    int divisorLength = rnd.Next(2, 50);
    //    string tempNumber1 = TestsHelper.GenerateRandomNumber(100, 1);
    //    string tempNumber2 = TestsHelper.GenerateRandomNumber(divisorLength, 0);
    //    number1 = (new FactoringBigNumber(tempNumber1)) / (new FactoringBigNumber(tempNumber2));
    //    number2 = (new StdBigNumber(tempNumber1)) / (new StdBigNumber(tempNumber2));
    //    Assert.IsTrue(number1.ToString() == number2.ToString(), String.Format("FactoringBigNumber was {0} and StdBigNumber was {1}", number1.ToString(), number2.ToString()));
    //  }
    //}

    //[Test]
    //public void TestFactoringBigNumberMod()
    //{
    //  FactoringBigNumber number1;
    //  StdBigNumber number2;
    //  Random rnd = new Random();
    //  for (int i = 0; i < TestsHelper.TEST_COUNT; i++)
    //  {
    //    int divisorLength = rnd.Next(2, 50);
    //    string tempNumber1 = TestsHelper.GenerateRandomNumber(100, 1);
    //    string tempNumber2 = TestsHelper.GenerateRandomNumber(divisorLength, 0);
    //    number1 = (new FactoringBigNumber(tempNumber1)) % (new FactoringBigNumber(tempNumber2));
    //    number2 = (new StdBigNumber(tempNumber1)) % (new StdBigNumber(tempNumber2));
    //    Assert.IsTrue(number1.ToString() == number2.ToString(), String.Format("FactoringBigNumber was {0} and StdBigNumber was {1}", number1.ToString(), number2.ToString()));
    //  }
    //}

    [Test]
    public void TestFactoringBigNumberCreatoinFull()
    {
      FactoringBigNumber number1;
      StdBigNumber number2;
      for (int i = 0; i < TestsHelper.TEST_COUNT; i++)
      {
        string tempNumber = TestsHelper.GenerateRandomNumber(NUMBER_LENGTH, 1);
        number1 = new FactoringBigNumber(tempNumber,FactorMode.Full);
        number2 = new StdBigNumber(tempNumber);
        Assert.IsTrue(number1.ToString() == number2.ToString());
      }
    }

    [Test]
    public void TestFactoringBigNumberSumFull()
    {
      FactoringBigNumber number1;
      StdBigNumber number2;
      for (int i = 0; i < TestsHelper.TEST_COUNT; i++)
      {
        string tempNumber1 = TestsHelper.GenerateRandomNumber(NUMBER_LENGTH, 1);
        string tempNumber2 = TestsHelper.GenerateRandomNumber(NUMBER_LENGTH, 1);
        number1 = (new FactoringBigNumber(tempNumber1, FactorMode.Full)) + (new FactoringBigNumber(tempNumber2, FactorMode.Full));
        number2 = (new StdBigNumber(tempNumber1)) + (new StdBigNumber(tempNumber2));
        Assert.IsTrue(number1.ToString() == number2.ToString(), String.Format("FactoringBigNumber was {0} and StdBigNumber was {1}", number1.ToString(), number2.ToString()));
      }
    }

    [Test]
    public void TestFactoringBigNumberSubFull()
    {
      FactoringBigNumber number1;
      StdBigNumber number2;
      for (int i = 0; i < TestsHelper.TEST_COUNT; i++)
      {
        string tempNumber1 = TestsHelper.GenerateRandomNumber(NUMBER_LENGTH, 1);
        string tempNumber2 = TestsHelper.GenerateRandomNumber(NUMBER_LENGTH, 1);
        number1 = (new FactoringBigNumber(tempNumber1)) - (new FactoringBigNumber(tempNumber2));
        number2 = (new StdBigNumber(tempNumber1)) - (new StdBigNumber(tempNumber2));
        Assert.IsTrue(number1.ToString() == number2.ToString(), String.Format("FactoringBigNumber was {0} and StdBigNumber was {1} while doing {2} - {3}", number1.ToString(), number2.ToString(), tempNumber1, tempNumber2));
      }
    }

    [Test]
    public void TestFactoringBigNumberMulFull()
    {
      FactoringBigNumber number1;
      StdBigNumber number2;
      for (int i = 0; i < TestsHelper.TEST_COUNT; i++)
      {
        string tempNumber1 = TestsHelper.GenerateRandomNumber(NUMBER_LENGTH, 1);
        string tempNumber2 = TestsHelper.GenerateRandomNumber(NUMBER_LENGTH, 1);
        number1 = (new FactoringBigNumber(tempNumber1, FactorMode.Full)) * (new FactoringBigNumber(tempNumber2, FactorMode.Full));
        number2 = (new StdBigNumber(tempNumber1)) * (new StdBigNumber(tempNumber2));
        //Console.WriteLine(tempNumber1 + " * " + tempNumber2);
        //Debug.Assert(number1.ToString() == number2.ToString());
        Assert.IsTrue(number1.ToString() == number2.ToString(), String.Format("FactoringBigNumber was {0} and StdBigNumber was {1} when doing {2} * {3}", number1.ToString(), number2.ToString(), tempNumber1, tempNumber2));
      }
    }

  }
}
